package hehe.validation.annotation;

import hehe.validation.base.Rule;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * ValidRule 验证规则注解处理器
 *<B>说明：</B>
 *<pre>
 * 略
 *</pre>
 *<B>示例：</B>
 *<pre>
 *  略
 *</pre>
 *<B>日志：</B>
 *<pre>
 *  略
 *</pre>
 *<B>注意事项：</B>
 *<pre>
 *  略
 *</pre>
 */
public class ValidRuleProcessor
{
    public void field(Class<?> targetClazz, Field field, Annotation annotation)
    {

        Rule rule = new Rule(field.getName());
        ValidRule validRuleAnn = (ValidRule) annotation;

        // 设置提示
        String tip = validRuleAnn.tip();
        if (!tip.equals("")) {
            rule.tip(tip);
        }

        String[] scene = validRuleAnn.scene();
        if (scene.length > 0) {
            rule.scene(scene);
        }

        boolean goOn = validRuleAnn.goOn();
        if (goOn == true) {
            rule.goOn();
        }

        String operator = validRuleAnn.operator();
        if (operator.equals(Rule.OR_OPERATOR)) {
            rule.or();
        }

        ValidAnnotation.addRule(targetClazz,field,rule);
    }

}
